package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.mapper.MarketSystemMapper;
import com.cskaoyan.market.service.AdminConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class AdminConfigServiceImpl implements AdminConfigService {

    @Autowired
    MarketSystemMapper marketSystemMapper;

    @Override
    public Map<String, Object> getOrderResponse() {
        Map<String, Object> data = new HashMap<>();
        Object commentValue = marketSystemMapper.seletValue("market_order_comment");
        Object unconfirmValue = marketSystemMapper.seletValue("market_order_unconfirm");
        Object unpaidValue = marketSystemMapper.seletValue("market_order_unpaid");
        data.put("market_order_comment",commentValue);
        data.put("market_order_unconfirm",unconfirmValue);
        data.put("market_order_unpaid",unpaidValue);
        return data;
    }

    @Override
    public Map<String, Object> getWxResponse() {
        Map<String, Object> data = new HashMap<>();
        Object list = marketSystemMapper.seletValue("market_wx_catlog_list");
        Object brand = marketSystemMapper.seletValue("market_wx_index_brand");
        Object hot = marketSystemMapper.seletValue("market_wx_index_hot");
        Object indexNew = marketSystemMapper.seletValue("market_wx_index_new");
        Object topic = marketSystemMapper.seletValue("market_wx_index_topic");
        Object share = marketSystemMapper.seletValue("market_wx_share");
        Object goods = marketSystemMapper.seletValue("market_wx_catlog_goods");
        data.put("market_wx_catlog_list",list);
        data.put("market_wx_index_brand",brand);
        data.put("market_wx_index_hot",hot);
        data.put("market_wx_index_new",indexNew);
        data.put("market_wx_index_topic",topic);
        data.put("market_wx_share",share);
        data.put("market_wx_catlog_goods",goods);
        return data;
    }

    @Override
    public Map<String, Object> getExpressResponse() {
        Map<String, Object> data = new HashMap<>();
        Object min = marketSystemMapper.seletValue("market_express_freight_min");
        Object value = marketSystemMapper.seletValue("market_express_freight_value");
        data.put("market_express_freight_min",min);
        data.put("market_express_freight_value",value);
        return data;
    }

    @Override
    public void modifyOrder(Map<String, String> marketWx) {
        String comment = marketWx.get("market_order_comment");
        String unconfirm = marketWx.get("market_order_unconfirm");
        String unpaid = marketWx.get("market_order_unpaid");
        marketSystemMapper.updateByName(comment,"market_order_comment");
        marketSystemMapper.updateByName(unconfirm,"market_order_unconfirm");
        marketSystemMapper.updateByName(unpaid,"market_order_unpaid");
    }

    @Override
    public void modifyWx(Map<String, String> marketWx) {
        String list = marketWx.get("market_wx_catlog_list");
        String brand = marketWx.get("market_wx_index_brand");
        String hot = marketWx.get("market_wx_index_hot");
        String indexnew = marketWx.get("market_wx_index_new");
        String topic = marketWx.get("market_wx_index_topic");
        String share = marketWx.get("market_wx_share");
        String goods = marketWx.get("market_wx_catlog_goods");
        marketSystemMapper.updateByName(list,"market_wx_catlog_list");
        marketSystemMapper.updateByName(brand,"market_wx_index_brand");
        marketSystemMapper.updateByName(hot,"market_wx_index_hot");
        marketSystemMapper.updateByName(indexnew,"market_wx_index_new");
        marketSystemMapper.updateByName(topic,"market_wx_index_topic");
        marketSystemMapper.updateByName(share,"market_wx_share");
        marketSystemMapper.updateByName(goods,"market_wx_catlog_goods");
    }

    @Override
    public void modifyExpress(Map<String, String> marketExpress) {
        String min = marketExpress.get("market_express_freight_min");
        String value = marketExpress.get("market_express_freight_value");
        marketSystemMapper.updateByName(min,"market_express_freight_min");
        marketSystemMapper.updateByName(value,"market_express_freight_value");
    }
}
